package com.jhws.core.shiro;

import com.jhws.core.shiro.execption.secLevelAccountEmptyException;
import org.apache.shiro.authc.*;
import org.apache.shiro.authc.pam.AbstractAuthenticationStrategy;
import org.apache.shiro.realm.Realm;
import org.springframework.data.redis.RedisConnectionFailureException;

/**
 * Created by Administrator on 2017/7/3.
 */
public class JHAuthenticationStrategy extends AbstractAuthenticationStrategy {

    @Override
    public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException {
        if (t != null) {
            if( t instanceof UnknownAccountException)
                throw (UnknownAccountException)t;
            else if( t instanceof ExcessiveAttemptsException)
                throw (ExcessiveAttemptsException)t;
            else if( t instanceof AccountException)
                throw (AccountException)t;
            else if( t instanceof IncorrectCredentialsException)
                throw (IncorrectCredentialsException)t;
            else if( t instanceof secLevelAccountEmptyException)
                throw (secLevelAccountEmptyException)t;
            else if( t instanceof RedisConnectionFailureException)
                throw (RedisConnectionFailureException)t;
        }
        return super.afterAttempt(realm,token,singleRealmInfo,aggregateInfo,t);
    }
}
